package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.service.SmsService;
import cn.gjculture.shopping.api.service.TokenService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/sms")
public class SmsController {

    @Autowired
    SmsService smsService;

    @Autowired
    TokenService tokenService;

    @ApiOperation(value = "发送短信验证码", notes = "发送短信验证码")
    @ApiImplicitParam(name = "phone", value = "手机号", required = true, dataType = "String")
    @PostMapping
    public void send(String phone){
        smsService.sendAuthCode(phone);
    }
    @PostMapping(value = "/verify")
    public Return verify(String id, String phone,String code){
        Return ret=new Return();
        if(this.smsService.verifyCode(id,phone,code)){
            ret.getCommon().setRet(true);
            ret.setData(tokenService.getToken(id));
        }
        return ret;
    }


}
